package com.ryan.mms.privilage.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.ryan.framework.action.BaseAction;
import com.ryan.framework.tag.pagination.PageHelper;
import com.ryan.framework.tag.pagination.PageParameterHelper;
import com.ryan.framework.tag.pagination.VPage;
import com.ryan.mms.privilage.dto.OperatorDto;
import com.ryan.mms.privilage.model.Operator;
import com.ryan.mms.privilage.service.OperatorService;

@Component
public class OperatorAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private OperatorDto operatorDto;
	
	@Autowired
	private OperatorService<OperatorDto,Operator,Long> operatorService;


	public String add() throws Exception {
		if(null!=operatorService.save(operatorDto)){
			return SUCCESS;
		}else{
			return ERROR;
		}
	}


	public String edit() throws Exception {

		return SUCCESS;
	}


	public String update() throws Exception {

		return SUCCESS;
	}



	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String list() throws Exception {
		Map map = (Map)ActionContext.getContext().get("request");
		// initialization the v page for paging
		HttpServletRequest request =ServletActionContext.getRequest();
		PageHelper pageHelper = new PageHelper(request);
		VPage vpage = PageParameterHelper.initVpage(pageHelper, request);
		map.put("vpage", vpage);
		return SUCCESS;
	}

	public String loadChangePassword(){
		return SUCCESS;
	}

	public OperatorDto getOperatorDto() {
		return operatorDto;
	}


	public void setOperatorDto(OperatorDto operatorDto) {
		this.operatorDto = operatorDto;
	}


	public void setOperatorService(
			OperatorService<OperatorDto, Operator, Long> operatorService) {
		this.operatorService = operatorService;
	}

}
